package com.noah.note.ui;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.noah.note.R;
import com.noah.note.global.BaseActivity;
import com.noah.note.presenter.RegisterPresenter;
import com.noah.note.utils.EncryptUtils;
import com.noah.note.view.RegisterView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * 注册
 */
public class RegisterActivity extends BaseActivity<RegisterPresenter> implements RegisterView {

    @BindView(R.id.etUsername)
    EditText etUsername;
    @BindView(R.id.etPassword)
    EditText etPassword;

    @Override
    protected RegisterPresenter initPresenter() {
        return new RegisterPresenter();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        ButterKnife.bind(this);
    }

    private void goRegister() {
        etUsername.setError(null);
        etPassword.setError(null);
        String username = etUsername.getText().toString();
        String password = EncryptUtils.MD5(etPassword.getText().toString());
        if (TextUtils.isEmpty(username) || username.length() < 6) {
            etUsername.setError(getString(R.string.error_username));
            etUsername.requestFocus();
            return;
        }
        if (TextUtils.isEmpty(password) || password.length() < 6) {
            etPassword.setError(getString(R.string.error_password));
            etPassword.requestFocus();
            return;
        }
//        mPresenter.register(username, password);
    }

    @OnClick(R.id.btnRegister)
    public void onViewClicked() {
        goRegister();
    }
}

